package com.ebupt.migu.music.effectStatistics.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ebupt.migu.music.common.auth.IDAuthUtils;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.util.EasyExcelUtil;
import com.ebupt.migu.music.common.util.ReqestParamUtil;
import com.ebupt.migu.music.effectStatistics.entity.vo.SMSDailyReportExportVo;
import com.ebupt.migu.music.effectStatistics.entity.vo.SmsExportVo;
import com.ebupt.migu.music.effectStatistics.service.SMSOperationService;

/**
 * @Author zhuar 短信运营
 */
@RestController
@RequestMapping("/SMSOperationController")
public class SMSOperationController {

    @Autowired
    private IDAuthUtils idAuthUtils;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private HttpServletResponse response;
    @Autowired
    private SMSOperationService smsOperationService;

    /**
     * 分页、条件查询 查询条件： 开始时间、结束时间、策略名称
     *
     * @return
     */
    @PostMapping("/queryMap")
    public ResultObject queryMap() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        params = idAuthUtils.isAdmin(params);
        return smsOperationService.queryMap(params);
    }

    /**
     * 效果统计 -- 目标人群条件查询 1-短信策略；2-banner策略；3-音乐之声策略；4-push策略
     * 
     * @return
     */
    @PostMapping("/targetUser")
    public ResultObject targetUser() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        params = idAuthUtils.isAdmin(params);
        return smsOperationService.targetUser(params);
    }

    /**
     * 查询条件： 开始时间、结束时间、策略名称 全量导出
     *
     * @return
     */
    @RequestMapping(value = "/exportMap", produces = MediaType.TEXT_HTML_VALUE)
    public void exportMap() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        params = idAuthUtils.isAdmin(params);
        List<SmsExportVo> list = smsOperationService.exportMap(params);
        EasyExcelUtil.export(response, SmsExportVo.class, list, "短信运营");
    }

    /**
     * 短信日报 分页、条件查询 查询条件： 开始时间、结束时间、策略名称
     *
     * @return
     */
    @PostMapping("/daily/report")
    public ResultObject report() {
        Map<String, Object> params = ReqestParamUtil.getParams(request);
        return smsOperationService.report(params);
    }

    /**
     * 日报导出
     *
     * @return
     */
    @RequestMapping(value = "/daily/exportMap", produces = MediaType.TEXT_HTML_VALUE)
    public void dailyExportMap() {
        Map<String, Object> params = ReqestParamUtil.getParams(request);
        List<SMSDailyReportExportVo> list = smsOperationService.dailyExportMap(params);
        EasyExcelUtil.export(response, SMSDailyReportExportVo.class, list, "短信日报");
    }
}